﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace huqiang.Core.HGUI
{
    public class MaterialBlock
    {
        public Texture[] textures = new Texture[8];
        int top = 1;
        public int CombinationTexture(Texture a)
        {
            for (int i = 0; i < top; i++)
            {
                if (textures[i] == a)
                {
                    return i;
                }
            }
            if (top < 8)
            {
                int id = top;
                textures[id] = a;
                top++;
                return id;
            }
            return -1;
        }
        public bool CombinationTexture(Texture[] ts, int[] ids, int count)
        {
            int l = 0;
            for (int i = 0; i < count; i++)
            {
                var t = ts[i];
                ids[i] = -1;
                for (int j = 0; j < top; j++)
                {
                    if (textures[j] == t)
                    {
                        ids[i] = j;
                        goto label;
                    }
                }
                l++;
                label:;
            }
            if (l + top > 8)
                return false;
            for (int i = 0; i < count; i++)
            {
                if (ids[i] < 0)
                {
                    ids[i] = top;
                    textures[top] = ts[i];
                    top++;
                }
            }
            return true;
        }
        public void Reset()
        {
            for (int i = 0; i < top; i++)
                textures[i] = null;
            top = 1;
        }
    }
}
